package com.dragon.refect.bytecode;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author dragon
 * @since 2019/12/9
 */
public class DynamicSubject implements InvocationHandler {

    private Subject subject;

    public DynamicSubject(Subject subject) {
        this.subject = subject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before calling: " + method);

        method.invoke(this.subject, args);

        System.out.println("after calling: " + method);

        return proxy;
    }
}
